package com.huike.business.service.impl;


import com.huike.business.domain.TbBusinessTrackRecord;
import com.huike.business.domain.vo.BusinessTrackVo;
import com.huike.business.mapper.TbBusinessTrackRecordMapper;
import com.huike.business.service.ITbBusinessTrackRecordService;
import com.huike.common.utils.SecurityUtils;
import com.huike.common.utils.bean.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 商机跟进记录Service业务层处理
 * 
 * @author wgl
 * @date 2021-04-28
 */
@Service
@Transactional
public class TbBusinessTrackRecordServiceImpl implements ITbBusinessTrackRecordService {

    @Autowired
    TbBusinessTrackRecordMapper tbBusinessTrackRecordMapper;

    @Override
    public Integer add(BusinessTrackVo businessTrackVo) {

        //1.获取当前操作用户
        String username = SecurityUtils.getUsername();
        //将前端传过来的VO转换为 tb_business_track_record 对象
        TbBusinessTrackRecord trackRecord = new TbBusinessTrackRecord();
        trackRecord.setCreateBy(username);
        BeanUtils.copyProperties(businessTrackVo,trackRecord);
        //调用mapper把tb_business_track_record对象 存进数据库
        tbBusinessTrackRecordMapper.add(trackRecord);
        //调用mapper把公海池的status状态改为2

        return tbBusinessTrackRecordMapper.updateWithStatus(trackRecord.getBusinessId());

    }

    @Override
    public List<TbBusinessTrackRecord> selectLog(Long id) {
        return tbBusinessTrackRecordMapper.selectLog(id);
    }
}
